/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Login;

import Dosen.DosenKontrol;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import rploo_ciayoo.kontrol.KoneksiDatabase;

/**
 *
 * @author asus
 */
public class LoginControl {

    private Connection conn;

    public LoginControl(Connection koneksi) {
        this.conn = koneksi;
    }

    public static LoginControl getKoneksi() throws SQLException {
        KoneksiDatabase konek = new KoneksiDatabase();
        LoginControl kon = new LoginControl(konek.getDBConnection());
        return kon;
    }
    
    public String cariPegawai(String kode) throws SQLException {
        PreparedStatement stmt = null;
        ResultSet result = null;
        String namanya = "";
        conn.setAutoCommit(false);
        String query = "SELECT password from login where id_petugas=? ";
        stmt = conn.prepareStatement(query);
        stmt.setString(1, kode);
        result = stmt.executeQuery();
        if (result.next()) {
            namanya = result.getString(1);
        }
        conn.commit();
        return namanya;
    }
    
//    public boolean LoginPetugas(String id,String password) throws SQLException {
////        PreparedStatement stmt = null;
//        boolean cek = false;
//        ResultSet result = null;
//        conn.setAutoCommit(false);
//        String query = ( "select id_petugas,password"
//                + "from login"
//                + "where id_petugas=? AND password=?");
//        stmt = conn.prepareStatement(query);
//        stmt.setString(1, id);
//        stmt.setString(2, password);
//       
//        result = stmt.executeQuery();
//        if (result.next()) {
//            cek = true;
//        }
//        conn.commit();
//        return cek;
//
//        PreparedStatement stat = null;
//        ResultSet result = null;
//        
//        conn.setAutoCommit(false);
//        stat = conn.prepareStatement( "select id_petugas,password"
//                + "from login"
//                + "where id_petugas=? AND password=?");
        
    
}
